//
//  HXCodeScreenViewController.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/15.
//

#import "HXCodeScreenViewController.h"

@interface HXCodeScreenViewController ()
@property (nonatomic,strong) UIImageView *passwordview;

@property (nonatomic,strong) UIImageView *filledone;//密码填充
@property (nonatomic,strong) UIImageView *filledtwo;//密码填充
@property (nonatomic,strong) UIImageView *filledthree ;//密码填充
@property (nonatomic,strong) UIImageView *filledfour ;//密码填充
@property (nonatomic,strong) UIImageView *filledfive ;//密码填充
@property (nonatomic,strong) UIImageView *filledsix ;//密码填充

@property (strong,nonatomic) NSString *timelb;
@property (assign,nonatomic) NSInteger indexValue;//记录点击成功下标
@property (assign,nonatomic) NSInteger tenHour;//24小时制十位。tenHour
@property (assign,nonatomic) NSInteger unitHour;//24小时制个位。unitHour
@property (assign,nonatomic) NSInteger tenMinute;//24小时制十分位。tenMinute
@property (strong,nonatomic) NSString *ultimateTime; //最终的时间;
@property (strong, nonatomic) BlueToothManager *blueToothManager;//蓝牙
@property (strong,nonatomic)  NSTimer* vibrationTimer;//震动计时器

@property (assign,nonatomic) BOOL isArrive;//是否到达
@end

@implementation HXCodeScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.fd_prefersNavigationBarHidden = YES;
    self.indexValue = 1;
    self.timelb = @"00:00";
    self.blueToothManager = [BlueToothManager shareInstance];
    [self.blueToothManager StartScan];//打开蓝牙
    [self addview];
  
}
-(void)addview{
    
    WeakSelf
    self.blueToothManager.datalasttimeBlock = ^(NSString * _Nonnull lasttime) {
        NSLog(@"获取设备返回来数据:%@",lasttime);
        NSArray *Arr = [NSArray array];
        Arr = [lasttime componentsSeparatedByString:@"0x585703"];
//        NSLog(@"获取最后的时间：%@",Arr);
        NSString *time = [Arr[1] substringWithRange:NSMakeRange(8, 2)];
        NSLog(@"time ：%@",time);
        if([time isEqualToString:@"02"]){
            [weakSelf stopvibration];//暂停震动
        }
        
    };
    
    NSInteger lockscreenheigth = 0;
    NSInteger passwordviewheigth = 0;
    
    NSInteger passwordviewbjheigth = 0;
    if(winHeight<=736){
        lockscreenheigth = 57;
        passwordviewheigth = 30;
    }else{
        lockscreenheigth = 20+57;
        passwordviewheigth = 50;

    }
    
    UIImageView *lockscreen = [[UIImageView alloc] init];
    lockscreen.image = [UIImage imageNamed:@"lockscreen"];
    [self.view addSubview:lockscreen];
    [lockscreen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lockscreenheigth);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(26);
        make.height.mas_equalTo(33);
    }];
    UIImageView *passwordview = [[UIImageView alloc] init];
    passwordview.image = [UIImage imageNamed:@"typeyoupassword"];
    [self.view addSubview:passwordview];
    [passwordview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lockscreen.mas_bottom).offset(passwordviewheigth);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(143);
    }];
    
    UIImageView *passwordviewbj = [[UIImageView alloc] init];
    [self.view addSubview:passwordviewbj];
    self.passwordview = passwordviewbj;
//    [passwordviewbj mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(46);
//        make.right.mas_equalTo(-46);
//        make.top.mas_equalTo(passwordview.mas_bottom).offset(140);
//        make.bottom.mas_equalTo(-170);
//    }];
    NSInteger emergencyheight = 0 ;
    if(winHeight<=736){
        [passwordviewbj mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(46);
            make.right.mas_equalTo(-46);
            make.top.mas_equalTo(passwordview.mas_bottom).offset(140);
            make.bottom.mas_equalTo(-60);
            
        }];
        emergencyheight = 10;
    }else{
        
        [passwordviewbj mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(46);
            make.right.mas_equalTo(-46);
            make.top.mas_equalTo(passwordview.mas_bottom).offset(140);
            make.bottom.mas_equalTo(-170);
        }];
        emergencyheight = 70;
    }
    
    
//    9.5*5+22*6
    UIImageView *mibj = [[UIImageView alloc] init];
//    mibj.backgroundColor = [UIColor whiteColor];
    mibj.userInteractionEnabled = YES;
    [self.view addSubview:mibj];
    [mibj mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(22);
        make.width.mas_equalTo(180);
        make.top.mas_equalTo(passwordview.mas_bottom).offset(50);
    }];
    
    UIImageView *codeone = [[UIImageView alloc] init];
    codeone.image = [UIImage imageNamed:@"notfilled"];
    self.filledone = codeone;
    [mibj addSubview:codeone];
    self.filledone = codeone;
    [codeone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
    }];
    
    
    UIImageView *codetwo = [[UIImageView alloc] init];
    codetwo.image = [UIImage imageNamed:@"notfilled"];
    self.filledtwo = codetwo;
    [mibj addSubview:codetwo];
    [codetwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
        make.left.mas_equalTo(codeone.mas_right).offset(9.5);
    }];
    UIImageView *codethree = [[UIImageView alloc] init];
    codethree.image = [UIImage imageNamed:@"notfilled"];
    self.filledthree = codethree;
    [mibj addSubview:codethree];
    [codethree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
        make.left.mas_equalTo(codetwo.mas_right).offset(9.5);
    }];
    UIImageView *codefour = [[UIImageView alloc] init];
    codefour.image = [UIImage imageNamed:@"notfilled"];
    self.filledfour = codefour;
    [mibj addSubview:codefour];
    [codefour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
        make.left.mas_equalTo(codethree.mas_right).offset(9.5);
    }];
    UIImageView *codefive = [[UIImageView alloc] init];
    codefive.image = [UIImage imageNamed:@"notfilled"];
    self.filledfive = codefive;
    [mibj addSubview:codefive];
    [codefive mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
        make.left.mas_equalTo(codefour.mas_right).offset(9.5);
    }];
    UIImageView *codesix = [[UIImageView alloc] init];
    codesix.image = [UIImage imageNamed:@"notfilled"];
    self.filledsix = codesix;
    [mibj addSubview:codesix];
    [codesix mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(22);
        make.left.mas_equalTo(codefive.mas_right).offset(9.5);
    }];
    [self addform];
//    emergency
    UIImageView *emergency = [[UIImageView alloc] init];
    emergency.image = [UIImage imageNamed:@"emergency"];
    [self.view addSubview:emergency];
    [emergency mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordview.mas_bottom).offset(emergencyheight);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(75);
        make.left.mas_equalTo(49);
    }];
    
    //    cancel
    UIImageView *cancel = [[UIImageView alloc] init];
    cancel.image = [UIImage imageNamed:@"cancel"];
    [self.view addSubview:cancel];
    [cancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordview.mas_bottom).offset(emergencyheight);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(45);
        make.right.mas_equalTo(-49);
    }];
    UIButton *cancelbt =[UIButton buttonWithType:UIButtonTypeCustom];
    [cancelbt addTarget:self action:@selector(cancelbt) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelbt];
    [cancelbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordview.mas_bottom).offset(emergencyheight);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(50);
        make.right.mas_equalTo(-49);
    }];
    

    self.blueToothManager.datalasttimeBlock = ^(NSString * _Nonnull lasttime) {
        NSLog(@"获取设备返回来数据:%@",lasttime);
        NSArray *Arr = [NSArray array];
        Arr = [lasttime componentsSeparatedByString:@"0x585703"];
//        NSLog(@"获取最后的时间：%@",Arr);
        NSString *time = [Arr[1] substringWithRange:NSMakeRange(8, 2)];
        NSLog(@"time ：%@",time);
        if([time isEqualToString:@"02"]){
            [weakSelf stopvibration];//暂停震动
        }
        
    };
    self.blueToothManager.ConnectionFailureBlock = ^(NSString * _Nonnull uuid) {
//        断开了链接
        NSLog(@"断开了链接。。。。");
        [[NSNotificationCenter defaultCenter]postNotificationName:@"bluetoothDisconnect" object:nil userInfo:@{@"uuid":uuid}];
        [weakSelf stopvibration];
        [weakSelf.blueToothManager StartScan];//打开蓝牙
        [weakSelf stopvibration];//暂停震动
    };
    
    self.blueToothManager.successfulConnectionBlock = ^(NSMutableArray * _Nonnull list) {
        NSLog(@"list %@",list);
        NSLog(@"链接成功");
//        [weakSelf resendTime];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           // 在子线程中执行需要延时的代码
           [NSThread sleepForTimeInterval:1.0]; // 休眠0.8秒钟

           dispatch_async(dispatch_get_main_queue(), ^{
              // 回到主线程中执行剩余操作

//               [weakSelf resendTime];
           });
        });
        [[NSNotificationCenter defaultCenter]postNotificationName:@"linkSuccess" object:nil userInfo:@{@"list":list}];
    };
}
-(void)addform{
    //自定义宫格边
    
    NSArray *imagearry = @[@"password1",@"password2",@"password3",@"password4",@"password5",@"password6",@"password7",@"password8",@"password9",@" d",@"password0",@"d"];
    
    NSInteger tag = 100;
    for (NSInteger i = 0; i < 4; i ++) {
        for (NSInteger j = 0; j < 3; j ++) {
            CGFloat btnW =  (winWidth-46-46-26.5-26.5)/3.00;
//            CGFloat btnH = (winHeight-160-140-kNavHeight-13.6-13.6-13.6)/4.0;
            CGFloat btnH = (winWidth-46-46-26.5-26.5)/3.00;
            CGFloat  btnX = j*btnW+j*26.5;
            CGFloat btnY = i*btnH+i*13.6;
            
            UIImageView *passwordview = [[UIImageView alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];
            passwordview.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",imagearry[tag-100]]];
            self.passwordview.userInteractionEnabled = YES;
            passwordview.userInteractionEnabled = YES;
            [self.passwordview addSubview:passwordview];
            
            UIButton *one = [UIButton buttonWithType:UIButtonTypeCustom];
            one.frame = CGRectMake(btnX, btnY, btnW, btnH);
            one.tag = tag ++;
            
            [self.passwordview addSubview:one];
            [one addTarget:self action:@selector(nuber:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    
    

}
-(void)cancelbt{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)nuber:(UIButton *)button{
    NSLog(@"点击了：%ld",button.tag-99);
    
//    [[UIScreen mainScreen] setBrightness:0];//亮度
//    方便返回
    if(button.tag == 111){

        return;
    }
    if(button.tag == 109){

        return;
    }
//    if (button.tag == 100) {
//        self.filledone.image = [UIImage imageNamed:@"filled"];
//    }else{
//        self.filledone.image = [UIImage imageNamed:@"notfilled"];
//    }
    
    //时间24小时制
    
    if(self.indexValue == 1){//第一次按钮
        //如果第一次点击，100 = 1  101 = 2  110 = 0 对应的按钮 那就是第一个位置
//        第一次点击了0 1 2 那就是24小时制第一个位置。
        if(button.tag == 100||button.tag == 101||button.tag == 110){
            NSString *time;
            if(button.tag == 110){//点击了0
                self.tenHour = 0;
                time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"0"];
                NSLog(@"time :%@",time);
            }else{
                time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
                self.tenHour = button.tag-99;
                NSLog(@"time :%@",time);
            }
            
            self.timelb = time;
            self.indexValue = 2;//第一个没问题
            self.filledone.image = [UIImage imageNamed:@"filled"];
            return;
            
        }else{
            NSString *time;
            //24小时制，如果第一个点击不是0 1 2  第一位那就是 0；
            time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"0"];
            self.timelb = [time stringByReplacingCharactersInRange:NSMakeRange(1, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
            self.indexValue = 3;//第一个
            self.tenHour = 0;
            self.filledone.image = [UIImage imageNamed:@"filled"];
            self.filledtwo.image = [UIImage imageNamed:@"filled"];
            return;
        }
        
    }
//    第二次点击 已经知道第一个是0 1 2
    if(self.indexValue == 2){
        NSLog(@"self.tenHour :%ld",self.tenHour);
//        如果第一个十位 是0 1 个位0-9都可以
        if(self.tenHour ==0 ||self.tenHour == 1){
            if(button.tag == 110){
                self.timelb = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(1, 1) withString:@"0"];
            }else{
                self.timelb = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(1, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
                
            }
            self.indexValue = 3;
            self.unitHour = button.tag-99;
            self.filledtwo.image = [UIImage imageNamed:@"filled"];
            return;
        }
        
        if(self.tenHour == 2){
            if(button.tag == 110 || button.tag == 100 || button.tag == 101|| button.tag == 102){
                NSString *time;
                if(button.tag == 110){//点击了0
                    self.unitHour = 0;
                    time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(1, 1) withString:@"0"];
                    NSLog(@"time :%@",time);
                }else{
                    time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(1, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
                    self.unitHour = button.tag-99;
                    NSLog(@"time :%@",time);
                }
                self.timelb = time;
                self.indexValue = 3;
                self.filledtwo.image = [UIImage imageNamed:@"filled"];
                return;
            }else{
                NSLog(@"小时十位是2 个位不能是%ld",button.tag-99);
            }
        }
       
    }
    
    if(self.indexValue == 3){//第三个数字
        NSLog(@"第三个数字 十分位置是：%ld",button.tag-99);
//        十分位tenMinute  最多
        if(button.tag == 100||button.tag == 101||button.tag == 102||button.tag == 103||button.tag == 104||button.tag == 110){
            NSString *time;
            if(button.tag == 110){//点击了0
                
                time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(3, 1) withString:@"0"];
                
            }else{
                time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(3, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
                
            }
            self.timelb = time;
            
            self.tenMinute = button.tag-99;
            self.indexValue = 4;
            self.filledthree.image = [UIImage imageNamed:@"filled"];
            return;
            NSLog(@"time :%@",time);
        }else{
            NSLog(@"十分位不能是：%ld",button.tag-99);
        }
        
    }
    if(self.indexValue == 4){
        
        NSString *time;
        if(button.tag == 110){//点击了0
            
            time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(4, 1) withString:@"0"];
            
        }else{
            time = [self.timelb stringByReplacingCharactersInRange:NSMakeRange(4, 1) withString:[NSString stringWithFormat:@"%ld",button.tag-99]];
        }
            NSLog(@"time :%@",time);
            self.timelb = time;
            self.indexValue = 5;
            self.ultimateTime = self.timelb;
            self.filledfour.image = [UIImage imageNamed:@"filled"];
        //只有四个，填完默认填充其余两个
            self.filledfive.image = [UIImage imageNamed:@"filled"];
            self.filledsix.image = [UIImage imageNamed:@"filled"];
//        发送蓝牙数据
            [self sendBluetoothData];
            return;
    }
    
    
    
}
-(void)sendBluetoothData{
    
    NSLog(@"发送蓝牙数据：%@",self.ultimateTime);
    NSArray *array = [self.ultimateTime componentsSeparatedByString:@":"];
    NSString * time = [NSString stringWithFormat:@"%@",array[0]];
    NSString * hour = [NSString stringWithFormat:@"%@",array[1]];
    int data = time.intValue;
    int tow = hour.intValue;
    NSLog(@"%d",data);
    if(data>12){
        data = data - 12;
    }
    data = [XHbluetoolUtils intTransitionhex16:data];
    tow = [XHbluetoolUtils intTransitionhex16:tow];
    Byte send[] = {0x58,0x57,0x03,0xff,0x00,data,tow,0x01};
    NSData *sendData = [NSData dataWithBytes:&send length:sizeof(send)];

    [self.blueToothManager writeData:sendData];
    if(data<10){
        self.ultimateTime = [NSString stringWithFormat:@"0%d:%@",data,hour];
    }else{
        self.ultimateTime = [NSString stringWithFormat:@"%d:%@",data,hour];
    }
    
    if (self.bluetoothtimeBlock) {
        self.bluetoothtimeBlock(self.ultimateTime);
    }
    //    存入蓝牙时间
    [[NSUserDefaults standardUserDefaults] setObject:self.ultimateTime forKey:@"Bluetoothtime"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [[NSUserDefaults standardUserDefaults] synchronize];
    
//    NSData *datastr = [self.ultimateTime dataUsingEncoding:NSUTF8StringEncoding];
//    [self.blueToothManager writeData:datastr];
    
//    if (@available(iOS 10.0, *)) {
//        UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];
//        [generator notificationOccurred:UINotificationFeedbackTypeWarning];
//    }
    
//    if(@available(iOS 10.0, *)){
//            UIImpactFeedbackGenerator *impactFeedBack = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleMedium];
//            [impactFeedBack prepare];
//            [impactFeedBack impactOccurred];
//        }
    
//    AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, nil);
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       // 在子线程中执行需要延时的代码
//        AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, nil);
       [NSThread sleepForTimeInterval:0.5]; // 休眠0.8秒钟

       dispatch_async(dispatch_get_main_queue(), ^{
          // 回到主线程中执行剩余操作
           [self getdataobtainrotationalstate];
           [self resettime];//重置时间
           
       });
    });
    
    
#pragma mark -退出app后台挂起
    
//    // Home键退出后台动画效果，此时后台还是挂起状态
//    [[UIApplication sharedApplication] performSelector:@selector(suspend)];
//
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//         // 杀掉应用，这里会有警告⚠️忽略即可，强迫症的话就使用exit(0)吧
////         [[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];
//    });
    
}
- (void)getdataobtainrotationalstate{
    
    Byte send[] = {0x58,0x57,0x03,0x0B,0x0,0x00,0x00,0x03};
    NSData *sendData = [NSData dataWithBytes:&send length:sizeof(send)];
    [self.blueToothManager writeData:sendData];
    if(self.blueToothManager.connectionState){
        NSLog(@"链接状态");
    }else{
        NSLog(@"未链接状态");
        NSLog(@"%@",self.ultimateTime);
        //    存入蓝牙时间
        [[NSUserDefaults standardUserDefaults] setObject:self.ultimateTime forKey:@"untraveledTime"];
        //这里建议同步存储到磁盘中，但是不是必须的
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    if(self.blueToothManager.bluetoothDiscoverable){
        NSLog(@"bluetoothDiscoverable链接状态");
    }else{
        NSLog(@"bluetoothDiscoverable 未链接状态");
        //    存入蓝牙时间
        [[NSUserDefaults standardUserDefaults] setObject:self.ultimateTime forKey:@"untraveledTime"];
        //这里建议同步存储到磁盘中，但是不是必须的
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, nil);
    [self.vibrationTimer invalidate];
    self.vibrationTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(playkSystemSound) userInfo:nil repeats:YES];
    
}
- (void)playkSystemSound{
//    获取现在是否走的，返回02就是走到正常的时间
    Byte send[] = {0x58,0x57,0x03,0x0B,0x0,0x00,0x00,0x08};
    NSData *sendData = [NSData dataWithBytes:&send length:sizeof(send)];
//    [self.blueToothManager writeData:sendData];
    [[BlueToothManager shareInstance] writeData:sendData];
    
//    AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, nil);
}

- (void)stopvibration{
    [self.vibrationTimer invalidate];
}

- (void)resettime{
    
    


        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           // 在子线程中执行需要延时的代码
           [NSThread sleepForTimeInterval:0.8]; // 休眠0.8秒钟

           dispatch_async(dispatch_get_main_queue(), ^{
              // 回到主线程中执行剩余操作
               self.indexValue = 1;
               self.tenHour = 0;
               self.timelb = @"00:00";
               self.ultimateTime = @"00:00";
               self.filledone.image = [UIImage imageNamed:@"notfilled"];
               self.filledtwo.image = [UIImage imageNamed:@"notfilled"];
               self.filledthree.image = [UIImage imageNamed:@"notfilled"];
               self.filledfour.image = [UIImage imageNamed:@"notfilled"];
               self.filledfive.image = [UIImage imageNamed:@"notfilled"];
               self.filledsix.image = [UIImage imageNamed:@"notfilled"];
           });
        });
        
  
    
//    self.indexValue = 1;
//    self.tenHour = 0;
//    self.timelb = @"00:00";
//    self.ultimateTime = @"00:00";
//    self.filledone.image = [UIImage imageNamed:@"notfilled"];
//    self.filledtwo.image = [UIImage imageNamed:@"notfilled"];
//    self.filledthree.image = [UIImage imageNamed:@"notfilled"];
//    self.filledfour.image = [UIImage imageNamed:@"notfilled"];
//    self.filledfive.image = [UIImage imageNamed:@"notfilled"];
//    self.filledsix.image = [UIImage imageNamed:@"notfilled"];
}
- (void)dealloc{
    if(self.isArrive){
        NSLog(@"跑到对应的时间");
    }else{
        NSLog(@"没跑到对应的时间");
        //    存入蓝牙时间
        [[NSUserDefaults standardUserDefaults] setObject:self.ultimateTime forKey:@"untraveledTime"];
        //这里建议同步存储到磁盘中，但是不是必须的
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    [self stopvibration];
}
- (void)resendTime{
    
    //    存入蓝牙时间NSString *arr= [[NSUserDefaults standardUserDefaults] objectForKey:@"theme"];
    NSString *resendTime= [[NSUserDefaults standardUserDefaults] objectForKey:@"untraveledTime"];
    if(kStringIsEmpty(resendTime)||[resendTime isEqualToString:@"无"]){
        NSLog(@"显示无。");
        return;
    }
    NSLog(@"resendTime :%@",resendTime);
    NSArray *array = [resendTime componentsSeparatedByString:@":"];
    NSString * time = [NSString stringWithFormat:@"%@",array[0]];
    NSString * hour = [NSString stringWithFormat:@"%@",array[1]];
    int data = time.intValue;
    int tow = hour.intValue;
    NSLog(@"%d",data);
    data = [XHbluetoolUtils intTransitionhex16:data];
    if(data>12){
        data = data - 12;
    }
    
    NSLog(@"12进制时间：%d",data);
    tow = [XHbluetoolUtils intTransitionhex16:tow];
    Byte send[] = {0x58,0x57,0x03,0xff,0x00,data,tow,0x01};
    NSData *sendData = [NSData dataWithBytes:&send length:sizeof(send)];
    self.isArrive = NO;//发送时no 到指定位置折为yes
    [self.blueToothManager writeData:sendData];
    [[NSUserDefaults standardUserDefaults] setObject:@"无" forKey:@"untraveledTime"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    //    存入蓝牙时间
    [[NSUserDefaults standardUserDefaults] setObject:resendTime forKey:@"Bluetoothtime"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
